package com.ruoyi.system.mapper;

import com.alibaba.fastjson2.JSONObject;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import com.ruoyi.system.domain.BySubjectClassify;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;


@Mapper
public interface BySubjectClassifyMapper {
    @Select("select *,'0' status from by_subject_classify where pid = #{id}")
    List<JSONObject> getNextSubjectList(@Param("id") String id);

    @Select("SELECT a.*,'0' status  FROM `by_subject_classify` a,by_bs_subject b where a.pid != 0 and a.id = b.`subject` and b.bsid = #{bsid}")
    List<JSONObject> getAllSubjectNoTopByBsId(@Param("bsid") String bsid);

    @Select("SELECT a.*,'0' status  FROM `by_subject_classify` a,by_bs_subject b where a.pid != 0 and a.id = b.`subject` and b.bsid = #{bsid}")
    List<JSONObject> getAllSubjectNoTopByBsIdAndDate(@Param("bsid") String bsid,@Param("date") String date);


    @Select("SELECT a.*,if((SELECT count(0) from by_bs_subject b where b.`subject` = a.id and b.bsid = #{bsid})>0,true,false) flag  FROM `by_subject_classify` a where a.pid = #{pid}")
    List<JSONObject> getAllSubjectNoTopForById(@Param("bsid") String bsid,@Param("pid")String pid);

    @Select("SELECT a.* FROM `by_subject_classify` a where a.pid = 0 and a.id != 0")
    List<JSONObject> getStageList();

    @Select("SELECT a.*,'0' status  FROM `by_subject_classify` a where a.pid != 0")
    List<JSONObject> getAllSubjectNoTop();

    @Select("select a.id, a.name, a.pid,'0' status, a.addtime, a.deleted,(select b.name from by_subject_classify b where b.id = a.pid) pidname from by_subject_classify a where id != 0 and pid = 0")
    List<BySubjectClassify> topBySubjectClassify();

    @Select("SELECT *,if(nCount > 0,concat(name,'(',nCount,')'),name) nams from " +
            "(select a.id,a.name, a.pid,'0' status, a.addtime, a.deleted," +
            "(select b.name from by_subject_classify b where b.id = a.pid) pidname,(SELECT count(0) from by_subject_classify c where c.pid = a.id) nCount" +
            " from by_subject_classify a where pid = #{pid}) t")
    List<JSONObject> querySubjectClassifyByPid(@Param("pid") String pid);
    /**
     * 查询学科分类
     *
     * @param id 学科分类主键
     * @return 学科分类
     */
    public BySubjectClassify selectBySubjectClassifyById(Long id);

    /**
     * 查询学科分类列表
     *
     * @param bySubjectClassify 学科分类
     * @return 学科分类集合
     */
    public List<BySubjectClassify> selectBySubjectClassifyList(BySubjectClassify bySubjectClassify);

    /**
     * 新增学科分类
     *
     * @param bySubjectClassify 学科分类
     * @return 结果
     */
    public int insertBySubjectClassify(BySubjectClassify bySubjectClassify);

    /**
     * 修改学科分类
     *
     * @param bySubjectClassify 学科分类
     * @return 结果
     */
    public int updateBySubjectClassify(BySubjectClassify bySubjectClassify);

    /**
     * 删除学科分类
     *
     * @param id 学科分类主键
     * @return 结果
     */
    public int deleteBySubjectClassifyById(Long id);

    /**
     * 批量删除学科分类
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteBySubjectClassifyByIds(Long[] ids);
}
